package cn.wlinker.video.monitor.utils;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.wlinker.video.monitor.domain.dto.MonitorDeviceDTO;
import org.springframework.util.Assert;

/**
 * 视频id工具类
 *
 * @author gxsjx
 * @version 1.0
 * @date 2022/11/8
 */
public class VideoKeyUtils {

    public static MonitorDeviceDTO getMonitorDeviceDtoById(String videoId) {
        String[] split = StrUtil.splitToArray(videoId, StrUtil.DASHED);
        Assert.isTrue(split != null && split.length > 2, "id不合法");
        MonitorDeviceDTO monitorDeviceDTO = new MonitorDeviceDTO();
        monitorDeviceDTO.setId(videoId);
        monitorDeviceDTO.setMonitorType(split[0]);
        monitorDeviceDTO.setAccessPlatform(split[1]);
        monitorDeviceDTO.setDeviceCode(split[2]);
        if (split.length > 3) {
            int channelNo = Integer.parseInt(split[3]);
            monitorDeviceDTO.setChannelNo(channelNo);
        }
        Integer channelNo = monitorDeviceDTO.getChannelNo();
        if (ObjectUtil.isEmpty(channelNo)) {
            monitorDeviceDTO.setChannelNo(1);
        }
        return monitorDeviceDTO;
    }
}
